﻿$(document).ready(function () {
	$(".price").keyup(function(){
		var num = $(this).val()
		num = commafy(num);
		$(this).val(num);
	});
    
	//format price ex: 5.000.000
	function commafy(Price) {
		Price = Price.replace(/\./g, "");
		Price = Price.replace(/\,/g, "");
		tmp = "";
		while (Price.length > 3)
		{
			tmp = "." + Price.substring(Price.length - 3) + tmp;
			Price = Price.substring(0, Price.length - 3);
			//alert(tmp + " " + Price );
		}
		tmp = Price + tmp;
		return tmp;
	}
	//text only input number
	$(".num").keydown(function(event) {
		// Allow: backspace, delete, tab, escape, and enter
		if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || 
		
		event.keyCode == 27 || event.keyCode == 13 || 
		// Allow: Ctrl+A
		(event.keyCode == 65 && event.ctrlKey === true) || 
		// Allow: home, end, left, right
		(event.keyCode >= 35 && event.keyCode <= 39)) {
		// let it happen, don't do anything
			return;
		}
		else {
		// Ensure that it is a number and stop the keypress
			if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && 
		
			(event.keyCode < 96 || event.keyCode > 105 )) {
				event.preventDefault(); 
			}   
		}
	});	
    //-------------- SessionLive --------------
    setInterval(function () {
        $.ajax({
            url: "/Shared/SessionLive/",
            type: "GET",
            data: $(this).serialize(),
            success: function () { }
        });
    }, 98 * 1000);
    //-------------- Kết thúc SessionLive --------------

    //-------------- TVC --------------
    setTimeout(function () {
        fActionYouTube('.vtc-video');
    }, 174000);
    //-------------- Kết thúc TVC --------------

    //-------------- Box Left Corner -----------
    var _boxLeftCorner = $(".ads-left-corner");
    var _boxLeftCornerAction = $(".ads-left-corner a.action");
    //var _widthLeftCorner = $(_boxLeftCorner).width();

    //$(_boxLeftCorner).css({ "width": "" + _widthLeftCorner + "px" });

    $(_boxLeftCornerAction).click(function () {
        if ($(this).hasClass("close")) {
            $(_boxLeftCorner).addClass("ads-left-corner-close");

            $(this).removeClass("close");
            $(this).addClass("open");
        }
        else {
            //$(_boxLeftCorner).css({ "width": "" + _widthLeftCorner + "px" });
            $(_boxLeftCorner).removeClass("ads-left-corner-close");

            $(this).removeClass("open");
            $(this).addClass("close");
        }
    });
    //-------------- End Box Left Corner -------

    //-------------- Box Promotion --------------
    var _boxPromotion = $(".box-promotion");
    var _boxPromotionItem = $(".box-promotion .box-promotion-item");
    var _boxPromotionImage = $(".box-promotion .box-promotion-item .box-banner img");
    var _boxPromotionClose = $(".box-promotion .box-promotion-close");

    var _widthSite = $(window).width();
    var _heightSite = $(window).height();

    var _widthBoxImage = $(_boxPromotionImage).width();
    var _heightBoxImage = $(_boxPromotionImage).height();

    if (_widthBoxImage < 100) _widthBoxImage = 500;
    if (_heightBoxImage < 100) _heightBoxImage = 300;

    $(_boxPromotionItem).css({ "width": "" + _widthBoxImage + "px"
                             , "height": "" + _heightBoxImage + "px"
                             , "left": "" + (_widthSite - _widthBoxImage) / 2 + "px"
                             , "top": "" + (_heightSite - _heightBoxImage) / 2 + "px"
    });

    setTimeout(function () {
        $(_boxPromotion).removeClass("box-promotion-active");
    }, 10000);

    $(_boxPromotion).click(function () {
        $(_boxPromotion).removeClass("box-promotion-active");
    });

    $(_boxPromotionClose).click(function () {
        $(_boxPromotion).removeClass("box-promotion-active");
    });

    $("html").keyup(function (e) {
        if (_boxPromotion != null)
            if (e.which == 27) {
                $(_boxPromotion).removeClass("box-promotion-active");

                _boxPromotion = null;
            }
    });
    //-------------- Kết thúc Box Promotion --------------

    //-------------- Ads --------------
    var _highStreet = $("#highstreet");
    var _highStreetAction = $("#highstreet .highstreet-inner .btn-highstreet a");

    $(_highStreetAction).click(function () {
        if ($(this).attr("rel") == "true") {
            $(this).removeClass("open");
            $(this).attr({ "rel": "false" });
            $(_highStreet).css({ "height": "0px" });
        }
        else {
            $(this).addClass("open");
            $(this).attr({ "rel": "true" });
            $(_highStreet).css({ "height": "189px" });
        }
    });
    //-------------- Kết thúc Ads --------------

    //    //-------------- Sản phẩm khuyến mại --------------
    //    var scrollPromotion = $(".pro-pm-list-box .pro-pm-item");
    //    var widthScrollItem = $(scrollPromotion).width();
    //    var leftScroll = parseInt($(scrollPromotion).css("left"));
    //    var totalScroll = -(widthScrollItem * 4);
    //    var scrollPromotion_Left = $(".pro-pm-list-box .pro-pm-scroll-left a");
    //    var scrollPromotion_Right = $(".pro-pm-list-box .pro-pm-scroll-right a");

    //    $(scrollPromotion_Right).click(function () {
    //        leftScroll = parseInt($(scrollPromotion).css("left"));
    //        if (leftScroll == totalScroll)
    //            leftScroll = widthScrollItem;
    //        //$(scrollPromotion).css({ "left": "" + (leftScroll - widthScrollItem) + "px" });
    //        $(scrollPromotion).animate({ left: "" + (leftScroll - widthScrollItem) + "px" }, 1000)
    //    });

    //    $(scrollPromotion_Left).click(function () {
    //        leftScroll = parseInt($(scrollPromotion).css("left"));
    //        if (leftScroll == 0)
    //            leftScroll = totalScroll;
    //        //$(scrollPromotion).css({ "left": "" + (leftScroll + widthScrollItem) + "px" });
    //        $(scrollPromotion).animate({ left: "" + (leftScroll + widthScrollItem) + "px" }, 1000)
    //    });
    //    //-------------- Kết thúc sản phẩm khuyến mại --------------

    //-------------- Sản phẩm khuyến mại, sản phẩm bán chạy, sản phẩm mới --------------
    var _proPmListMenu = $(".pro-pm-list ul.pro-pm-list-menu li a");
    var _proPmListView = $(".pro-pm-list .pro-pm-list-box .pro-pm-item");

    $(_proPmListMenu).mouseenter(function () {
        $(_proPmListMenu).removeClass("active");
        $(this).addClass("active");

        $(_proPmListView).removeClass("pro-pm-item-active");
        $(_proPmListView).eq($(this).attr("rel")).addClass("pro-pm-item-active");
    });
    //-------------- Kết thúc Sản phẩm khuyến mại, sản phẩm bán chạy, sản phẩm mới --------------

    //-------------- Banner trang chủ --------------

    var _objBannerHomeTitle = $("ul.banner-home-title li a");
    var _objBannerHomeItem = $("ul.banner-home-item li");
    var _objBannerHomeItemImage_Current;
    var _currentBannerHomeItem = 0;

    var refreshInterval_BannerHome = setInterval(function () {

        _currentBannerHomeItem += 1;
        if (_currentBannerHomeItem >= 5)
            _currentBannerHomeItem = 0;

        _objBannerHomeItemImage_Current = $(_objBannerHomeItem).eq(_currentBannerHomeItem).find("img");

        if ($(_objBannerHomeItemImage_Current).attr("rel") != "") {
            $(_objBannerHomeItemImage_Current).attr("src", $(_objBannerHomeItemImage_Current).attr("rel"));
            $(_objBannerHomeItemImage_Current).attr("rel", "");
        }
        $(_objBannerHomeItem).css({ "display": "none" });
        $(_objBannerHomeItem).eq(_currentBannerHomeItem).css({ "display": "block" });
    }, 200000);

    $(_objBannerHomeTitle).mouseenter(function () {
        clearInterval(refreshInterval_BannerHome);

        $(_objBannerHomeTitle).removeClass("active");
        $(this).addClass("active");

        _currentBannerHomeItem = $(this).parent().prevAll().length;
        $(_objBannerHomeItem).css({ "display": "none" });

        _objBannerHomeItemImage_Current = $(_objBannerHomeItem).eq(_currentBannerHomeItem).find("img");

        if ($(_objBannerHomeItemImage_Current).attr("rel") != "") {
            $(_objBannerHomeItemImage_Current).attr("src", $(_objBannerHomeItemImage_Current).attr("rel"));
            $(_objBannerHomeItemImage_Current).attr("rel", "");
        }
        $(_objBannerHomeItem).eq(_currentBannerHomeItem).css({ "display": "block" });
    }).mouseleave(function () {
        refreshInterval_BannerHome = setInterval(function () {

            _currentBannerHomeItem += 1;
            if (_currentBannerHomeItem >= 5)
                _currentBannerHomeItem = 0;

            _objBannerHomeItemImage_Current = $(_objBannerHomeItem).eq(_currentBannerHomeItem).find("img");

            if ($(_objBannerHomeItemImage_Current).attr("rel") != "") {
                $(_objBannerHomeItemImage_Current).attr("src", $(_objBannerHomeItemImage_Current).attr("rel"));
                $(_objBannerHomeItemImage_Current).attr("rel", "");
            }
            $(_objBannerHomeItem).css({ "display": "none" });
            $(_objBannerHomeItem).eq(_currentBannerHomeItem).css({ "display": "block" });
        }, 10000);
    });

    //-------------- Kết thúc banner trang chủ --------------

    fCategory_Tree();

    fZoomProduct();

    fScroll_TBS();

    //-------------- Menu danh mục sản phẩm --------------
    var _pathName = window.location.pathname;
    var _objMenuMouse = $(".menu .menu-hori .menu-pc");
    var _objMenu = $(".menu .menu-hori .menu-pc .menu-verti");
    if (_pathName == "/" || _pathName == "") {
        $(_objMenu).addClass("menu-verti-active");
    }
    else {
        $(_objMenuMouse).mouseenter(function () {
            $(_objMenu).fadeIn('slow');
            $(_objMenu).addClass("menu-verti-active");
        }).mouseleave(function () {
            $(_objMenu).css({ 'display': 'none' });
            $(_objMenu).removeClass("menu-verti-active");
        });
    }

    var _objMenuVertiMouse = $(".menu ul.menu-hori li.menu-pc ul.menu-verti li.menu-verti-i-0 a.a-menu-verti-0");
    var _objMenuVertiActive;
    var _objMenuHoriMouse;

    $(_objMenuVertiMouse).mouseenter(function () {
        //Tag A
        _objMenuVertiActive = $(this);
        _objMenuVertiActive.addClass("a-menu-verti-0-active");

        //Tag Ul
        _objMenuHoriMouse = $(this).parent("li.menu-verti-i-0").find("ul.menu-hori-1");
        $(_objMenuHoriMouse).addClass("menu-hori-1-active");

        $(_objMenuHoriMouse).mouseenter(function () {
            //Tag A
            _objMenuVertiActive.addClass("a-menu-verti-0-active");
            //Tag Ul
            $(this).addClass("menu-hori-1-active");
        }).mouseleave(function () {
            //Tag A
            _objMenuVertiActive.removeClass("a-menu-verti-0-active");
            //Tag Ul
            $(this).removeClass("menu-hori-1-active");
        });

    }).mouseleave(function () {
        //Tag A
        $(this).removeClass("a-menu-verti-0-active");
        //Tag Ul
        $(_objMenuHoriMouse).removeClass("menu-hori-1-active");
    });
    //-------------- Kết thúc menu danh mục sản phẩm --------------

    //-------------- Thông số sản phẩm --------------
    var _pIntroductAction = $(".p-introduct ul.p-introduct-title li a");
    var _pIntroductView = $(".p-introduct div.p-introduct-content");
    var _pIntroduct = $(".p-introduct");
    var _idPIntroductView;
    $(_pIntroductAction).click(function () {
        $(_pIntroductAction).removeClass("active");
        $(this).addClass("active");

        _idPIntroductView = $(this).attr('rel');

        $(_pIntroductView).removeClass("p-introduct-content-active");
        $(_pIntroduct).find(_idPIntroductView).addClass("p-introduct-content-active");
    });
    //-------------- Kết thúc thông số sản phẩm --------------

    //-------------- Gói bảo hành --------------
    var _pOrderWarrantyAction = $(".p-order-warranty #productOrderWarrantyId");
    var _pOrderWarrantyPrice = $(".p-order-warranty .p-order-warranty-price");
    var _pDetailOrder_AddOrderWarranty = $(".pro-detail .p-order-buy");

    var _pDetailOrder_Val = "";

    $(_pOrderWarrantyAction).change(function () {
        $(_pOrderWarrantyPrice).html($(this).find("option:selected").attr("rel"));

        _pDetailOrder_Val = $(_pDetailOrder_AddOrderWarranty).attr("href");
        _pDetailOrder_Val = _pDetailOrder_Val.split("++")[0] + "++" + $(this).val() + "+";

        $(_pDetailOrder_AddOrderWarranty).attr("href", _pDetailOrder_Val);

        //alert(_pDetailOrder_Val);
    });
    //-------------- Kết thúc Gói bảo hành --------------

    //-------------- Gói đặc biệt --------------
    var _pPackageSpecialAction = $(".p-package-special ul.p-package-title a");
    var _pPackageSpecialView = $(".p-package-special ul.p-package-special");
    $(_pPackageSpecialAction).click(function () {
        $(_pPackageSpecialAction).removeClass("active");
        $(this).addClass("active");

        $(_pPackageSpecialView).removeClass("p-package-special-active");
        $(_pPackageSpecialView).eq($(this).attr('rel')).addClass("p-package-special-active");
    });
    //-------------- Kết thúc Gói đặc biệt --------------

    //-------------- Gói phụ kiện --------------
    var _pPackageAction = $(".p-packageaccesscombined ul.p-package-title a");
    var _pPackageView = $(".p-packageaccesscombined div.p-package-item");
    $(_pPackageAction).click(function () {
        $(_pPackageAction).removeClass("active");
        $(this).addClass("active");

        $(_pPackageView).removeClass("p-package-item-active");
        $(_pPackageView).eq($(this).attr('rel')).addClass("p-package-item-active");
    });
    //-------------- Kết thúc Gói phụ kiện --------------

    //-------------- Gói phụ Cập nhật giá Gói phụ kiện --------------
    var _pPackageAccessAction = $(".p-package-access .p-package-cb input:checkbox");
    var _pPackageAccessView = $(".p-package-access .p-package-right-access");

    var _pPackageAccessSelect = $(_pPackageAccessView).find(".p-pa-rg-select span");
    var _pPackageAccessPrice = $(_pPackageAccessView).find(".p-pa-rg-price");
    var _pPackageAccessPriceMarket = $(_pPackageAccessView).find(".p-pa-rg-pricemarket");
    var _pPackageAccessOrder = $(_pPackageAccessView).find(".p-pa-rg-order a");
    $(_pPackageAccessAction).click(function () {
        if ($(this).attr('checked')) {
            $(_pPackageAccessSelect).html(parseInt($(_pPackageAccessSelect).html()) + 1);

            $(_pPackageAccessPrice).attr({ "rel": parseInt($(_pPackageAccessPrice).attr("rel")) + parseInt($(this).attr("rel")) });

            getFormatPrice($(_pPackageAccessPrice).attr("rel"), _pPackageAccessPrice);

            $(_pPackageAccessOrder).attr({ "href": $(_pPackageAccessOrder).attr("href") + "+" + $(this).attr("id").replace("pa-pi-", "") + "+" });
        } else {
            $(_pPackageAccessSelect).html(parseInt($(_pPackageAccessSelect).html()) - 1);

            $(_pPackageAccessPrice).attr({ "rel": parseInt($(_pPackageAccessPrice).attr("rel")) - parseInt($(this).attr("rel")) });

            getFormatPrice($(_pPackageAccessPrice).attr("rel"), _pPackageAccessPrice);

            $(_pPackageAccessOrder).attr({ "href": $(_pPackageAccessOrder).attr("href").replace("+" + $(this).attr("id").replace("pa-pi-", "") + "+", "") });
        }
    });

    //-------------- Kết thúc Cập nhật giá Gói phụ kiện --------------
});

//-------------- ProductCategoryTree --------------
function fCategory_Tree() {
    var objTree_Root = $("ul.tree li.tree-i .a-tree-0");
    var objTree_Node;
    $(objTree_Root).mouseenter(function () {
        $(objTree_Root).parents(".tree-i-0").find("ul.tree-1").css({ "display": "none" });

        objTree_Node = $(this).parents(".tree-i-0").find("ul.tree-1");
        objTree_Node.css({ "display": "block" });

        $(objTree_Node).mouseenter(function () {

        }).mouseleave(function () {
            objTree_Node.css({ "display": "none" });
        });
    }).mouseleave(function () {
        //objTree_Node.css({ "display": "none" });
    });
}
//-------------- Kết thúc ProductCategoryTree --------------

//-------------- Fix --------------
function fPosition_Fix() {
    var _height_ScrollTop_Detail = 0;
    var _height_Fix = 238;
    var _height_Limit = $(".wrap-pd").height();
    var _height_Position = 0;
    var _objPosition_Fix = $(".wrap-pd .wrap-left-pd");
    var _objHiddenImage_Fix = $(".wrap-pd .wrap-left-pd .pro-image-list");
    var _objHiddenBox_Fix = $(".wrap-pd .wrap-left-pd .pro-price-fix");

    $(window).scroll(function () {
        _height_ScrollTop_Detail = $(window).scrollTop();
        _height_Limit = $(".wrap-pd").height();
        _height_Position = parseInt(parseInt(_height_ScrollTop_Detail) - parseInt(_height_Limit - 347));

        if (parseInt(_height_ScrollTop_Detail) > parseInt(_height_Fix) && _height_Position < 0) {
            if ($(_objPosition_Fix).hasClass('wrap-left-pd-fix') == false) {
                $(_objPosition_Fix).addClass('wrap-left-pd-fix');
                $(_objPosition_Fix).css({ 'top': '7px' });
                $(_objHiddenImage_Fix).addClass('pro-image-list-hidden');
                $(_objHiddenBox_Fix).removeClass('pro-price-fix-hidden');
            }
        }
        else if (parseInt(_height_ScrollTop_Detail) > parseInt(_height_Fix)) {
            $(_objPosition_Fix).css({ "top": "-" + parseInt(_height_Position) + "px" });
        }
        else if ((parseInt(_height_ScrollTop_Detail) < parseInt(_height_Fix))) {
            $(_objPosition_Fix).removeClass('wrap-left-pd-fix');
            $(_objHiddenImage_Fix).removeClass('pro-image-list-hidden');
            $(_objHiddenBox_Fix).addClass('pro-price-fix-hidden');
        }
    });
};
//-------------- EndFix --------------

//-------------- Slideshow ảnh chi tiết sản phẩm --------------
function fChangeImage(objAction, img) {
    $(objAction).css({ 'display': 'none' }).attr({ 'src': img }).fadeIn('slow');
}
//-------------- Kết thúc Slideshow ảnh chi tiết sản phẩm --------------

//-------------- Định dạng giá --------------
function getFormatPrice(price, objAction) {
    if (price != "") {
        $.ajax({
            url: "/eSystem/Shared/FormatPrice/?price=" + price,
            type: "POST",
            data: "json",
            success: function (msg) {
                $.each(msg, function (key, val) {
                    $(objAction).html(val);
                });
            }
        });
    }
};
//-------------- Kết thúc Định dạng giá --------------

//-------------- TVC --------------
function fActionYouTube(viewObjYouTube) {
    $(viewObjYouTube).parent().html("<embed width='304' height='240' wmode='transparent' type='application/x-shockwave-flash' src='" + $(viewObjYouTube).attr("rel") + "&amp;autoplay=1&amp;rel=0&amp;loop=1&amp;playlist=" + $(viewObjYouTube).attr("rel1") + "' />");
};
//-------------- Kết thúc TVC --------------

//-------------- Search AutoComplete --------------
function SearchAutoComplete(urlPost, objThis, objAction) {
	
    var _keyword = $(objThis).val();
    var _strResult = "";
    if (_keyword.length >= 3) {
        urlGet = urlPost + _keyword
		//alert(urlGet); return false;
        $.ajax({
            url: urlGet,
            type: "POST",
            data: "json",
            success: function (msg) {
                var objJson = eval(msg);
                if (objJson != null) {
                    for (var i = 0; i < objJson.length; i++) {
                        _strResult += "<div class='autocomplete-item'>";

                        _strResult += "<div class='img'>";
                        _strResult += "<img  src='" + objJson[i].Images + "'>";
                        _strResult += "</div>";

                        _strResult += "<div class='content'>";
                        _strResult += "<a target='_self' href='" + objJson[i].Images2 + "' title='" + objJson[i].TenTivi + "'>" + objJson[i].TenTivi + "</a>";
                        _strResult += "<span><span class='price'>Giá: " + objJson[i].GiaBan + "</span></span>"
                        _strResult += "</div>";

                        _strResult += "</div>";
                    }
                    $(objAction).html(_strResult);
                    $(objAction).css({ 'display': 'block' });

                    $(objAction).mouseleave(function () {
                        $(objAction).css({ 'display': 'none' });
                    });
                }
                else
                    $(objAction).css({ 'display': 'none' });
            }
        });
    }
    else if (_keyword == '') {
        $(objAction).css({ 'display': 'none' });
    }
};

//-------------- AjaxCallBack --------------
function fAjaxBegin_PL() {
    $('html, body').animate({ scrollTop: 250 }, 500);
};
function fAjaxCallBack_PL() {
    fCategory_Tree();
    fZoomProduct();
};
//-------------- Kết thúc AjaxCallBack --------------

//-------------- Zoom Product --------------
function fZoomProduct() {
    var _objZP_Li = $("#ajax-temp-pro ul.temp-pro-item li.temp-pro-item-li");
    var _objZP_Li_Active = $("#ajax-temp-pro ul.temp-pro-item li.temp-pro-item-active");
    var _objZP_A = $("#ajax-temp-pro ul.temp-pro-item li.temp-pro-item-li a.zp");
    var _objZP_Li_Current;
    var _objZP_Rel_Current;


    var _objZP_Rel_Old;

    var _objZP_Li_Each;
    var _objZP_Rel_Each;

    var _addTop = 0;
    var _sizeTop = 0;
    var _sizeLeft = 0;
    var _checkFirst = false;

    //Product
    var _objProductUrl;
    var _objZP_Append;
    var _urlGetZP;
    var _strAppendZP;
    var _objJsonZP;

    var _zP_Product_Href;
    var _zP_Product_ProductName;
    var _zP_Product_ProductImageUrl;
    var _zP_Product_ProductPriceMarket;
    var _zP_Product_ProductPrice;
    var _zP_Product_Sku;
    var _zP_Product_Model;
    var _zP_Product_Description;
    var _zP_Product_SpecialOffer;
    var _zP_Product_ListProductImageUrl;

    $(_objZP_A).click(function () {
        //Default
        _objZP_Li_Current = $(this).parent().parent();
        _objZP_Rel_Current = parseInt($(_objZP_Li_Current).attr("rel"));

        //Current
        $(_objZP_Li_Current).addClass("temp-pro-item-active");
        //Current - Spec
        _objZP_Append = $(_objZP_Li_Current).find("div.temp-pro-item-content");
        _objProductUrl = $(this).attr("rel");
        if (_objProductUrl.length >= 3) {
            _urlGetZP = "/mo-ta-ngan/" + _objProductUrl + ".htm";
            $.ajax({
                url: _urlGetZP,
                type: "GET",
                success: function (msg) {
                    _strAppendZp = msg;

                    $(_objZP_Append).html(_strAppendZp);
                    fHoverLPI_ZP();
                }
            });
        }

        //Current - Position
        _sizeTop = (parseInt(_objZP_Rel_Current / 4) + 1) * 252;
        $(_objZP_Li_Current).animate({
            width: "952px",
            height: "333px",
            top: "" + _sizeTop + "px",
            left: "0"
        }, 500);

        //Fix
        _checkFirst = false;
        _addTop = 0;
        _sizeTop = 0;
        _sizeLeft = 0;
        $(_objZP_Li).each(function () {
            _objZP_Rel_Each = parseInt($(this).attr("rel"));

            if (_objZP_Rel_Each != _objZP_Rel_Current) {
                //AddTop
                if (_objZP_Rel_Each > _objZP_Rel_Current && _checkFirst == false) {

                    if (parseInt((_objZP_Rel_Each - 1) % 4) == 0 && (_objZP_Rel_Each - 1) != _objZP_Rel_Current) {
                        _addTop = 335;
                        _checkFirst = true;
                    }
                }

                //Size
                if ($(this).hasClass("temp-pro-item-active")) {
                    _objZP_Rel_Old = parseInt($(this).attr("rel"));
                    if (_objZP_Rel_Old >= (_objZP_Rel_Current + 1)) {
                        _objZP_Rel_Old -= 1;
                    }
                    _sizeTop = parseInt(_objZP_Rel_Old / 4) * 252 + _addTop;
                    _sizeLeft = parseInt(_objZP_Rel_Old % 4) * 244;

                    $(this).animate({
                        width: "220px",
                        height: "250px",
                        top: "" + _sizeTop + "px",
                        left: "" + _sizeLeft + "px"
                    }, 100);

                    $(this).removeClass("temp-pro-item-active");
                }
                else {
                    if (_objZP_Rel_Each <= _objZP_Rel_Current) {
                        _sizeTop = parseInt(_objZP_Rel_Each / 4) * 252 + _addTop;
                        _sizeLeft = parseInt(_objZP_Rel_Each % 4) * 244;

                        $(this).css({ "top": "" + _sizeTop + "px", "left": "" + _sizeLeft + "px" });
                    }
                    else {
                        _objZP_Rel_Each -= 1;
                        _sizeTop = parseInt(_objZP_Rel_Each / 4) * 252 + _addTop;
                        _sizeLeft = parseInt(_objZP_Rel_Each % 4) * 244;

                        $(this).css({ "top": "" + _sizeTop + "px", "left": "" + _sizeLeft + "px" });
                    }
                }
            }
        });

        return false;
    });
};
//-------------- Kết thúc Zoom Product --------------

//-------------- Hover List Product Image - ZP--------------
function fHoverLPI_ZP() {
    var _objLPI_ZP = $(".temp-pro-item-content .zp-pd-center ul li a");
    var _objLPI_ZP_View = $(".temp-pro-item-content .zp-pd-left p img");

    $(_objLPI_ZP).mouseenter(function () {
        //alert($(this).attr("rel"));
        $(_objLPI_ZP_View).attr({ "src": "" + $(this).attr("rel") + "" });
    });
};
//-------------- Kết thúc Hover List Product Image - ZP --------------

//-------------- Top Sản Phẩm--------------
function fScroll_TBS() {

    var _obj_TBS_L = $(".pl-scroll a.pl-c-l");
    var _obj_TBS_R = $(".pl-scroll a.pl-c-r");
    var _obj_TBS_V = $(".pl-scroll .pl-c-c ul.pl-c-c-l");
    var _obj_TBS_D = 940;
    var _obj_TBS_W = 0 - parseInt($(_obj_TBS_V).attr("rel"));
    var _obj_TBS_P_L = 0;

    //Left
    $(_obj_TBS_L).click(function () {
        _obj_TBS_P_L = parseInt($(_obj_TBS_V).css("left"));

        if (_obj_TBS_P_L < 0)
            _obj_TBS_P_L = _obj_TBS_P_L + _obj_TBS_D;
        else
            _obj_TBS_P_L = 0;

        $(_obj_TBS_V).animate({
            left: "" + _obj_TBS_P_L + "px"
        }, 200);
    });

    //Right
    $(_obj_TBS_R).click(function () {
        _obj_TBS_P_L = parseInt($(_obj_TBS_V).css("left"));

        if (_obj_TBS_P_L - _obj_TBS_D > _obj_TBS_W)
            _obj_TBS_P_L = _obj_TBS_P_L - _obj_TBS_D;

        $(_obj_TBS_V).animate({
            left: "" + _obj_TBS_P_L + "px"
        }, 200);
    });

};
//-------------- Kết thúc Top Sản Phẩm --------------

//--------------checkbox checkALL-------------------
function MouseEvents(objRef, evt) {

    var checkbox = objRef.getElementsByTagName("input")[0];
    
    if (evt.type == "mouseover") {

        objRef.style.backgroundColor = "#D7EBFF";

    }

    else {

        if (checkbox.checked) {

            objRef.style.backgroundColor = "#D7EBFF";

        }

  
        else if (evt.type == "mouseout") {

            //if (objRef.rowIndex % 2 == 0) {

            //Alternating Row Color

            //objRef.style.backgroundColor = "#C2D69B";

            //}

            //else {

            objRef.style.backgroundColor = "white";

            // }

        }

    }

}

    function checkAll(objRef) {

        var GridView = objRef.parentNode.parentNode.parentNode;

        var inputList = GridView.getElementsByTagName("input");

        for (var i = 0; i < inputList.length; i++) {

            //Get the Cell To find out ColumnIndex

            var row = inputList[i].parentNode.parentNode;

            if (inputList[i].type == "checkbox" && objRef != inputList[i]) {

                if (objRef.checked) {

                    //If the header checkbox is checked

                    //check all checkboxes

                    //and highlight all rows

                    //row.style.backgroundColor = "#D7EBFF";

                    inputList[i].checked = true;

                }

                else {

                    //If the header checkbox is checked

                    //uncheck all checkboxes

                    //and change rowcolor back to original

                    //if (row.rowIndex % 2 == 0) {

                        //Alternating Row Color

                        //row.style.backgroundColor = "#C2D69B";

                    //}

                    //else {

                        //row.style.backgroundColor = "white";

                    //}

                    inputList[i].checked = false;

                }

            }

        }

    }

    function Check_Click(objRef) {

        //Get the Row based on checkbox

        var row = objRef.parentNode.parentNode;

        if (objRef.checked) {

            //If checked change color to Aqua

            //row.style.backgroundColor = "#D7EBFF";

        }

        else {

            //If not checked change back to original color

           // if (row.rowIndex % 2 == 0) {

                //Alternating Row Color

                //row.style.backgroundColor = "#C2D69B";

            //}

            //else {

                //row.style.backgroundColor = "white";

            //}

        }



        //Get the reference of GridView

        var GridView = row.parentNode;



        //Get all input elements in Gridview

        var inputList = GridView.getElementsByTagName("input");



        for (var i = 0; i < inputList.length; i++) {

            //The First element is the Header Checkbox

            var headerCheckBox = inputList[0];



            //Based on all or none checkboxes

            //are checked check/uncheck Header Checkbox

            var checked = true;

            if (inputList[i].type == "checkbox" && inputList[i] != headerCheckBox) {

                if (!inputList[i].checked) {

                    checked = false;

                    break;

                }

            }

        }

        headerCheckBox.checked = checked;



    }

